package com.bilin.coin.activity;

import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bilin.coin.R;
import com.bilin.coin.bean.BiLinWallet;
import com.bilin.coin.bean.GoldBean;
import com.bilin.coin.bean.GoldBeanWrag;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.tools.AbsHeadRecycleViewActivity;
import com.bilin.coin.tools.Geter;
import com.bilin.coin.tools.Poster;
import com.bilin.coin.utils.GsonUtil;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Route(path = "/auction/GoldBeanDetailActivity")
public class GoldBeanDetailActivity extends AbsHeadRecycleViewActivity<GoldBeanWrag.RecordsBean> {

    private TextView tv_gold_num;
    private TextView tv_gold_num_f;

    @Override
    protected void initView() {
        super.initView();
        setTitle("金豆明细");
        getWallet();
    }

    @Override
    protected void convertItem(BaseViewHolder helper, GoldBeanWrag.RecordsBean item) {
        helper.setText(R.id.tv_note,item.getNote());
        helper.setText(R.id.tv_time,item.getCreateTime());

        String latestUsable = item.getUsable();
        TextView tv_usable = helper.getView(R.id.tv_usable);
        if (Double.parseDouble(latestUsable) > 0) {
            tv_usable.setTextColor(getResources().getColor(R.color.colorBlue));
            helper.setText(R.id.tv_usable, "+"+latestUsable);
        } else {
            tv_usable.setTextColor(getResources().getColor(R.color.red_common2));
            helper.setText(R.id.tv_usable, ""+latestUsable);
        }

    }



    @Override
    protected int fillItemLayout() {
        return R.layout.item_gold;
    }

    @Override
    public int fillPageSize() {
        return 15;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public String fillUrl() {
        return "/api/bl-user-jd-log/list";
    }

    private void getWallet() {
        new Geter(this, false, true) {
            @Override
            protected String fillUrl() {
                return "/api/bl-wallet/getMoney";
            }

            @Override
            protected Map<String, String> fillParams() {
                return new HashMap<>();
            }

            @Override
            protected void disposeSuccess(String dataJson) {
                super.disposeSuccess(dataJson);
                BiLinWallet biLinWallet = GsonUtil.GsonToBean(dataJson, BiLinWallet.class);
                tv_gold_num.setText(biLinWallet.getJd());
            }
        };
    }

    @Override
    protected View fillHeadView() {
        View view = View.inflate(this,R.layout.head_gold_bean_detail, null);
        tv_gold_num = view.findViewById(R.id.tv_gold_num);
        tv_gold_num_f = view.findViewById(R.id.tv_gold_num_f);
        view.findViewById(R.id.tv_buy).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sell();
            }
        });
        view.findViewById(R.id.tv_recharge_gold).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                baseStartActivity("/auction/SellGoldRecordActivity");
            }
        });
        return view;
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage", page + "");
        params.put("pageSize", pageSize + "");
        return params;
    }

    @Override
    public List<GoldBeanWrag.RecordsBean> parseListDataAndFillTotal(String dataJson) {
        GoldBeanWrag goldBeanWrag = GsonUtil.GsonToBean(dataJson, GoldBeanWrag.class);
        totalCount = goldBeanWrag.getTotal();
        return goldBeanWrag.getRecords();
    }

    @Override
    protected void initData() {

    }


    @Override
    protected RecyclerView.LayoutManager fillLayoutManger() {
        return super.fillLayoutManger();
    }

    @Override
    protected void refreshFragmentOrHead() {
        getWallet();
    }

    private void sell() {
        baseStartActivity("/auction/SellGoldActivity");
    }
}
